home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c++-part2 / 12724 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.8 KB  |  72 lines

  1. Path: news2.noc.netcom.net!news
  2. From: Sean Palmer <sean@delta.com>
  3. Newsgroups: comp.lang.c++
  4. Subject: buffered streambuf in BC++4.52
  5. Date: Mon, 18 Mar 1996 22:36:32 -0500
  6. Organization: deltaComm Development, Inc.
  7. Message-ID: <314E2BC0.F3A@delta.com>
  8. NNTP-Posting-Host: landspeeder.delta.com
  9. Mime-Version: 1.0
  10. Content-Type: text/plain; charset=us-ascii
  11. Content-Transfer-Encoding: 7bit
  12. X-Mailer: Mozilla 2.0 (Win95; I)
  13.  
  14. Hi, I can't seem to get a buffered version of a streambuf to work in 
  15. Borland C++ 4.52. Their docs are kinda skimpy, assuming you know all 
  16. about iostreams already. If you can make this sample work or can email 
  17. me a small working sample, thanks!
  18.  
  19. Here's my non-working try:
  20.  
  21. //.h file
  22. #include <iostream.h>
  23.  
  24. struct debugstrbuf : streambuf {
  25.   debugstrbuf();
  26.   virtual int overflow(int c=EOF);
  27.   virtual int doallocate();
  28.   virtual int sync();
  29. protected:
  30.   char buf[258];
  31.   };
  32.  
  33. //.cpp file
  34. static debugstrbuf globaldebugbuf;
  35.  
  36. debugstrbuf::debugstrbuf() {
  37.   cerr = &globaldebugbuf;
  38.   clog = &globaldebugbuf;
  39.   cout = &globaldebugbuf;
  40.   allocate();
  41.   }
  42.  
  43. int debugstrbuf::overflow(int c) {
  44.   if (c==EOF) c=0;
  45.   *pptr()=(char)c;
  46.   if (c) pptr()[1]=0;
  47.   OutputDebugString(pbase());
  48.   doallocate();
  49.   return 0;
  50.   }
  51. int debugstrbuf::doallocate() {
  52.   enum { sz=sizeof(buf)-2 };
  53.   setbuf(buf,sz);
  54.   setp(buf,&buf[sz]);
  55.   return sz;
  56.   }
  57. int debugstrbuf::sync() { return 1; } //have tried 0
  58.  
  59. In any case, subsequent attempts to do:
  60.  
  61.   cerr << "something" << endl;
  62.  
  63. don't seem to do anything, but occasionally will overflow and cause some 
  64. severe kind of lockup.
  65.  
  66. I think I could handle it if I knew what the functions like setp and 
  67. setbuf did, and how the various data members of streambuf were being 
  68. manipulated by the iostream, but that's all hidden away and assumed that 
  69. you know it already... So I'm just guessing.
  70.  
  71. Thanks! Please reply via e-mail..
  72.